
#include "BfcpTransportEventThread.hxx"
#include "BfcpStack.hxx"
#include "rutil/BaseException.hxx"
#include "zklog/zklog_wrapper.h"

using namespace resip;


namespace bfcp
{
    BfcpTransportEventThread::BfcpTransportEventThread(BfcpStack& stack, resip::FdPollGrp& grp)
        : mStack(stack), mPollGrp(grp)
    {
        mStack.setPollGrp(&mPollGrp);
    }

    BfcpTransportEventThread::~BfcpTransportEventThread()
    {
        mStack.setPollGrp(0);
    }

    void BfcpTransportEventThread::thread()
    {
        while (!isShutdown())
        {
            try
            {
                mStack.process();
                mPollGrp.waitAndProcess(25);
            }
            catch (BaseException& e)
            {
                ZKLOG_ERROR << "Unhandled exception: " << e;
            }
        }
        ZKLOG_INFO << "Shutting down bfcp stack event thread";
    }

}
